#!/bin/sh

#
# Cleanup left over files -- both before and after test run
#

. scripts/functions

if [ ! -f ${working}/CLEANUPMARKER ]; then
    print_debug "SKIPPED: cleanup. Looks like it is already clean."
    exit 0
fi

cwd=`pwd`

rm -rf ${tmp}/*
rm -rf ${working}/log
rm -rf ${working}/*.bsr ${working}/log*.sd
rm -rf ${working}/*.trace ${working}/*.traceback ${working}/*.bactrace
rm -rf ${working}/*.state
rm -rf ${working}/CLEANUPMARKER
rm -rf ${working}/plugins/*
find . -name "gigaslam.gif" -exec rm -f {} \;
# cleanup old config files
# don't delete mtx-changer.conf (and other files?)
rm -f  ${conf}/*.cert
rm -f  ${conf}/susan*.conf
rm -f  ${conf}/bconsole*.conf
rm -rf ${conf}/*.d/
rm -f  ${conf}/*.pem
rm -rf ${conf}/susan-dir-export/
rm -rf ${conf}/tls/


# bin directory does not always exist
if [ -d ${scripts} ]; then
  if [ -f ${scripts}/susan ]; then
     ${scripts}/susan stop 2>&1 >/dev/null
  fi
  ${scripts}/drop_susan_tables ${DBTYPE} >/dev/null 2>&1
  print_debug "creating database (${DBTYPE})"
  ${scripts}/create_susan_tables ${DBTYPE} >/dev/null 2>&1
  ${scripts}/make_susan_tables ${DBTYPE} >/dev/null 2>&1
  ${scripts}/grant_susan_privileges ${DBTYPE} >/dev/null 2>&1
fi

